module CurveFitting_module
  implicit none
contains

	subroutine cfLeastSquareRegression(X, Y, slope, intercept)
		real, allocatable, dimension(:), intent(in)	:: 	X, Y
		real, intent(inout)							:: 	slope, intercept
		real, allocatable, dimension(:)	:: 	square_err
		real							:: 	sumx, sumy, sumx2
		integer							::	i
		integer							:: 	n

		sumx = 0
		sumy = 0 
		sumx2 = 0
		n = size(X, dim = 1)

		do i = 1, n
			sumx = sumx + X(i)
			sumy = sumy + Y(i)
			sumx2 = sumx2 + X(i)*X(i)
		end do

		slope = (n*DOT_PRODUCT(X,Y) - sumx*sumy)/(n*sumx2 - sumx**2)
		intercept = sumy/n - slope*sumx/n
	end subroutine cfLeastSquareRegression
end module CurveFitting_module			

